package com.luxiu;


import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Structure;


/**
 * Hello world!
 */
public class App {

    // 顺序要和C中结构体成员定义顺序一致
    @Structure.FieldOrder({"x", "y"})
    public static class Size extends Structure {
        public int x;
        public int y;

        @Override
        public String toString() {
            return "Size{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }
    }

    public interface Dll extends Library {
        Dll instance = Native.load("Dll", Dll.class);

        int add(int a, int b);

        void getStructure(Size size);

        Size getStructure2();

        String getString();
    }

    public static void main(String[] args) {
        Dll dll = Dll.instance;

        System.out.println("1 + 2 = " + dll.add(1, 2));
        System.out.println("getString: " + dll.getString());
        Size size = new Size();
        dll.getStructure(size);
        System.out.println("getStructure: " + size);
        System.out.println("getStructure2: " + dll.getStructure2());
    }
}
